#include "Tiles.h"
#include <GL/freeglut.h>
#include <iostream>

/////////////////////////////////////////////////////////////////////
//////////////////////////////FREE TILE IMPL/////////////////////////
/////////////////////////////////////////////////////////////////////

Tile::Tile()
{

}

Tile::~Tile()
{

}

void Tile::Render(int x, int y, int width, int height)
{
	// get the color of the tile
	GLColor color;
	getColor(color);

	// draw a filled in rectangle with the color
	glColor3f(color.r, color.g, color.b);
	glRecti(x, y, x + width, y + height);

	// draw a border around each tile
	glBegin(GL_LINES);
		glColor3f(0.0, 0.0, 0.0);
		// first line segment
		glVertex2i(x, y);
		glVertex2i(x + width, y);
		
		//second line segment
		glVertex2i(x + width, y);
		glVertex2i(x + width, y + height);

		//third line segment
		glVertex2i(x + width, y + height);
		glVertex2i(x, y + height);

		//fourth line segment
		glVertex2i(x, y + height);
		glVertex2i(x, y);
	glEnd();
}

FreeTile::FreeTile()
{

}

FreeTile::~FreeTile()
{

}

bool FreeTile::IsTravellable()
{
	return true;
}

int FreeTile::TravelCost()
{
	return 0;
}

void FreeTile::getColor(GLColor &color)
{
	color.r = 0.96;
	color.g = 0.87;
	color.b = 0.70;
	color.a = 0.0;
}

Tile* FreeTile::Consume()
{
	return NULL;
}

/////////////////////////////////////////////////////////////////////
//////////////////////////////DIRT TILE IMPL/////////////////////////
/////////////////////////////////////////////////////////////////////

DirtTile::DirtTile()
{

}

DirtTile::~DirtTile()
{

}

bool DirtTile::IsTravellable()
{
	return true;
}

int DirtTile::TravelCost()
{
	return 1;
}

void DirtTile::getColor(GLColor &color)
{
	color.r = 0.55;
	color.g = 0.27;
	color.b = 0.07;
	color.a = 0.0;
}

Tile* DirtTile::Consume()
{
	return new FreeTile();
}

/////////////////////////////////////////////////////////////////////
//////////////////////////////ROCK TILE IMPL/////////////////////////
/////////////////////////////////////////////////////////////////////

RockTile::RockTile()
{

}

RockTile::~RockTile()
{

}

bool RockTile::IsTravellable()
{
	return false;
}

int RockTile::TravelCost()
{
	return 100;
}

void RockTile::getColor(GLColor &color)
{
	color.r = 0.0;
	color.g = 0.0;
	color.b = 0.0;
	color.a = 0.0;
}

Tile* RockTile::Consume()
{
	return NULL;
}

/////////////////////////////////////////////////////////////////////
//////////////////////////////GOAL TILE IMPL/////////////////////////
/////////////////////////////////////////////////////////////////////

GoalTile::GoalTile()
{

}

GoalTile::~GoalTile()
{

}

bool GoalTile::IsTravellable()
{
	return true;
}

int GoalTile::TravelCost()
{
	return 100;
}

void GoalTile::getColor(GLColor &color)
{
	color.r = 1.0;
	color.g = 1.0;
	color.b = 1.0;
	color.a = 0.0;
}

Tile* GoalTile::Consume()
{
	// should fire game over?
	return NULL;
}